﻿using AutoMapper;
using MediatR;
using S.Archives.Api.Application.Command.Wander;
using S.Archives.Domain.S.ArchivesModel;
using S.Archives.Infrstructre.InterFace;

namespace S.Archives.Api.Application.CommandHandlers.Wander
{
    public class WanderCreateCommandHandler : IRequestHandler<WanderCreateCommand, bool>
    {
        private readonly IWanderRepository wanderRepository;
        private readonly IMapper mapper;
        public WanderCreateCommandHandler(IWanderRepository wanderRepository, IMapper mapper)
        {
            this.wanderRepository = wanderRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 流转信息添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(WanderCreateCommand request, CancellationToken cancellationToken)
        {
            WanderModel wanderModel = mapper.Map<WanderModel>(request);
            return await wanderRepository.AddAsync(wanderModel);
        }
    }
}
